/**
 * Pangolin IM Server
 * autor:   yiyefangzhou24
 * email:   yiyefangzhou24@qq.com
 * data:    21/10/1
 */

#ifndef PANGOLINSERVER_MYSQL_H
#define PANGOLINSERVER_MYSQL_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
#include "package.h"
#include "config.h"

#define MAX_SQL_LEN 5120
#define MESSAGE_BUFF_MAX_LEN 4096           //该数值应该设定为PACKAGE_BUFF_MAX_LEN2倍，因为base64编码不超过原来长度2倍

bool init_mysql_pool(char * host , int port , char * user , char * pass, char * db);
void close_mysql_pool();
const char * mysql_getlasterror();
int mysql_add_user(char * username , char * passwd , int * uid);
bool mysql_check_login(int uid, char * passwd);
bool mysql_find_user(int uid , char * username , char * headimg);
int mysql_update_pass(int uid , char * newpasswd);
int mysql_update_userinfo(int uid , char * username , char * headimg);
int mysql_push_msg_queue(int fromuid , int touid , char *msg);
//int mysql_get_msg_num(int uid);
int mysql_pull_msg(int uid , char msg[20][MESSAGE_BUFF_MAX_LEN]);
int mysql_add_friendlist(int from , int to , int remark);
int mysql_update_friendlist(int from , int to , int remark);
int mysql_get_allfriendlist(int ** list);
int mysql_get_friendlist(int uid , int * uid_list , char ** name_list , char ** headimg_list);
int mysql_del_relationship(int from , int to);
int mysql_count_row(char * table , char * where);
int mysql_get_friendlistremark(int fromuid , int touid);

#endif //PANGOLINSERVER_MYSQL_H